generator client {
    provider = "prisma-client-js"
}

datasource db {
    provider = "mysql"
    url      = env("DATABASE_URL")
}

enum Role {
    USER
    ADMIN
}

model User {
    id       Int     @id @default(autoincrement())
    email    String  @unique
    phone    String
    name     String
    role     Role
    password String
    Order    Order[]

    @@map("users")
}

enum OrderStatus {
    PROCESSING
    PREPARING
    DELIVERY
    COMPLETED
}

model Order {
    id          Int         @id @default(autoincrement())
    user        User        @relation(fields: [userId], references: [id])
    userId      Int
    address     String
    description String?
    count       Int
    createdAt   DateTime    @default(now())
    OrderItem   OrderItem[]
    status      OrderStatus @default(PROCESSING)
}

model OrderItem {
    id         Int   @id @default(autoincrement())
    order      Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
    orderId    Int
    menuItem   Item  @relation(fields: [menuItemId], references: [id], onDelete: Cascade)
    menuItemId Int
    quantity   Int
}

model ItemCategory {
    id   Int    @id @default(autoincrement())
    name String

    items Item[]
}

model Item {
    id          Int          @id @default(autoincrement())
    name        String
    description String
    price       Decimal
    photo       Bytes
    category    ItemCategory @relation(fields: [categoryId], references: [id])
    categoryId  Int
    stop        Boolean      @default(false)

    OrderItem OrderItem[]
}
